<template>
	<transition name="el-zoom-in-center">
		<div class="JNPF-preview-main">
			<div class="JNPF-common-page-header">
				<el-page-header @back="goBack" :content="!dataForm.id ? '新建' : isDetail ? '详情' : '编辑'"/>
				<div class="options">
					<el-button type="primary" @click="dataFormSubmit()" v-if="!isDetail">确 定</el-button>
					<el-button @click="goBack">取 消</el-button>
				</div>
			</div>
			<el-row :gutter="15"  class="main" :style="{margin: '0 auto',width:'100%'}">
			<el-form ref="elForm" :model="dataForm" size="medium" label-width="180px" label-position="right" :disabled="!!isDetail" :rules="rules">
				<el-col :span="12">
					<el-form-item label="库房编码" prop="kfbm" required >
						<el-input v-model="dataForm.kfbm" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="库房名称" prop="kfmc" required >
						<el-input v-model="dataForm.kfmc" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="库区编号" prop="kqbh" required >
						<el-select v-model="dataForm.kqbh" placeholder="请选择" clearable :style='{"width":"100%"}' >
							<el-option v-for="(item, index) in kqbhOptions" :key="index" :label="item.KQMC" :value="item.KQBH" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="物品状态" prop="wpzt" required >
						<el-input v-model="dataForm.wpzt" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="物品类别" prop="wzlb" required >
						<el-input v-model="dataForm.wzlb" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="库房序号" prop="kfxh" required >
						<el-input v-model="dataForm.kfxh" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="火灾危险性分类" prop="hzwxxfl" required >
						<el-radio-group v-model="dataForm.hzwxxfl" :style='{}' >
							<el-radio v-for="(item, index) in hzwxxflOptions" :key="index" :label="item.id"  >{{item.fullName}}</el-radio>
						</el-radio-group>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="有无防火墙" prop="ywfhq" required >
						<el-radio-group v-model="dataForm.ywfhq" :style='{}' >
							<el-radio v-for="(item, index) in ywfhqOptions" :key="index" :label="item.id"  >{{item.fullName}}</el-radio>
						</el-radio-group>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="所属部门" prop="ssbm" required >
						<el-select filterable v-model="dataForm.ssbm" placeholder="请选择" clearable :style='{"width":"100%"}' >
							<el-option v-for="(item, index) in ssbmOptions" :key="index" :label="item.F_FullName" :value="item.F_Id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="所在位置" prop="szwz" required >
						<el-input v-model="dataForm.szwz" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="贮存面积" prop="zcmj" required >
						<el-input v-model="dataForm.zcmj" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="库房形式" prop="kfxs" required >
						<el-input v-model="dataForm.kfxs" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="贮存物资名称" prop="zcwzmc" required >
						<el-input v-model="dataForm.zcwzmc" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="设计储量" prop="sjcl" required >
						<el-input v-model="dataForm.sjcl" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="危险货物编号" prop="wxhwbh" required >
						<el-input v-model="dataForm.wxhwbh" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="CAS号" prop="cash" >
						<el-input v-model="dataForm.cash" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="是否剧毒化学品仓库" prop="sfjdhxpck" required >
						<el-radio-group v-model="dataForm.sfjdhxpck" :style='{}' >
							<el-radio v-for="(item, index) in sfjdhxpckOptions" :key="index" :label="item.id"  >{{item.fullName}}</el-radio>
						</el-radio-group>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="投产日期" prop="tcrq" required >
						<el-date-picker v-model="dataForm.tcrq" placeholder="请选择" clearable :style='{"width":"100%"}' type="date" format="yyyy-MM-dd" value-format="timestamp" >
						</el-date-picker>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="经度（度）" prop="jd" required >
						<el-input v-model="dataForm.jd" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="纬度（度）" prop="wd" required >
						<el-input v-model="dataForm.wd" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="所属重大危险源单元编号" prop="sszdwxydyh" >
						<el-select v-model="dataForm.sszdwxydyh" placeholder="请选择" clearable :style='{"width":"100%"}' >
							<el-option v-for="(item, index) in sszdwxydyhOptions" :key="index" :label="item.ZDWXYMC" :value="item.ZDWXYBM" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="现场照片" prop="xczp" >
						<JNPF-UploadImg v-model="xczpList" accept="" :fileSize="20" sizeUnit="MB" :limit="9" >
						</JNPF-UploadImg>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="备注" prop="bz" >
						<el-input v-model="dataForm.bz" placeholder="请输入" show-word-limit :style='{"width":"100%"}' type="textarea" :autosize='{"minRows":4,"maxRows":4}' >
						</el-input>
					</el-form-item>
				</el-col>
			</el-form>
			</el-row>
		</div>
	</transition>

</template>
<script>
import request from '@/utils/request'
import {getDictionaryDataSelector}from '@/api/systemData/dictionary'
import {previewDataInterface}from '@/api/systemData/dataInterface'
export default {
    data() {
      return {
        visible: false,
        isDetail: false,
        dataForm: {
					kfbm:undefined,
					kfmc:undefined,
					kqbh:undefined,
					wpzt:undefined,
					wzlb:undefined,
					kfxh:undefined,
					hzwxxfl:undefined,
					ywfhq:undefined,
					ssbm:undefined,
					szwz:undefined,
					zcmj:undefined,
					kfxs:undefined,
					zcwzmc:undefined,
					sjcl:undefined,
					wxhwbh:undefined,
					cash:undefined,
					sfjdhxpck:undefined,
					tcrq:undefined,
					jd:undefined,
					wd:undefined,
					sszdwxydyh:undefined,
					xczp:[],
					bz:undefined,

        },
        rules: {
						kfbm:[
						{
							required:true,
							message:'请输入库房编码',
							trigger:'blur'
						},
						],
						kfmc:[
						{
							required:true,
							message:'请输入库房名称',
							trigger:'blur'
						},
						],
						kqbh:[
						{
							required:true,
							message:'请输入库区编号',
							trigger:'blur'
						},
						],
						wpzt:[
						{
							required:true,
							message:'请输入物品状态',
							trigger:'blur'
						},
						],
						wzlb:[
						{
							required:true,
							message:'请输入物品类别',
							trigger:'blur'
						},
						],
						kfxh:[
						{
							required:true,
							message:'请输入库房序号',
							trigger:'blur'
						},
						],
						hzwxxfl:[
						{
							required:true,
							message:'请输入火灾危险性分类',
							trigger:'blur'
						},
						],
						ywfhq:[
						{
							required:true,
							message:'请输入有无防火墙',
							trigger:'blur'
						},
						],
						ssbm:[
						{
							required:true,
							message:'请输入所属部门',
							trigger:'blur'
						},
						],
						szwz:[
						{
							required:true,
							message:'请输入所在位置',
							trigger:'blur'
						},
						],
						zcmj:[
						{
							required:true,
							message:'请输入贮存面积',
							trigger:'blur'
						},
						],
						kfxs:[
						{
							required:true,
							message:'请输入库房形式',
							trigger:'blur'
						},
						],
						zcwzmc:[
						{
							required:true,
							message:'请输入贮存物资名称',
							trigger:'blur'
						},
						],
						sjcl:[
						{
							required:true,
							message:'请输入设计储量',
							trigger:'blur'
						},
						],
						wxhwbh:[
						{
							required:true,
							message:'请输入危险货物编号',
							trigger:'blur'
						},
						],
						sfjdhxpck:[
						{
							required:true,
							message:'请输入是否剧毒化学品仓库',
							trigger:'blur'
						},
						],
						tcrq:[
						{
							required:true,
							message:'请输入投产日期',
							trigger:'blur'
						},
						],
						jd:[
						{
							required:true,
							message:'请输入经度（度）',
							trigger:'blur'
						},
						],
						wd:[
						{
							required:true,
							message:'请输入纬度（度）',
							trigger:'blur'
						},
						],

        },
				kqbhOptions:[],
				hzwxxflOptions:[{"fullName":"甲类","id":"1"},{"fullName":"乙类","id":"2"},{"fullName":"丙类","id":"3"}],
				ywfhqOptions:[{"fullName":"无","id":"0"},{"fullName":"有","id":"1"}],
				ssbmOptions:[],
				sfjdhxpckOptions:[{"fullName":"否","id":"0"},{"fullName":"是","id":"1"}],
				sszdwxydyhOptions:[],

					xczpList:[],

      }
    },
    created() {
		this.getkqbhOptions();
		this.getssbmOptions();
		this.getsszdwxydyhOptions();

    },
    methods: {
		getkqbhOptions()
		{
			previewDataInterface('5cd8b3e8c47e4a3faf42a8dd05f220af').then(res => {
				this.kqbhOptions = res.data
			})
		},
		getssbmOptions()
		{
			previewDataInterface('772d2cbcadd24df79243e3d92ef5f690').then(res => {
				this.ssbmOptions = res.data
			})
		},
		getsszdwxydyhOptions()
		{
			previewDataInterface('707f1102bce74818a551ebcfa88f2321').then(res => {
				this.sszdwxydyhOptions = res.data
			})
		},

           goBack() {
                    this.$emit('refresh')
                },
      init(id, isDetail) {

        this.dataForm.id = id || 0;
        this.visible = true;
        this.isDetail = isDetail || false;
        this.$nextTick(() => {
          this.$refs['elForm'].resetFields();
          if (this.dataForm.id) {
            request({
              url: '/api/System/qyscKf/' + this.dataForm.id,
              method: 'get'
            }).then(res =>{
              this.dataForm = res.data;
				this.xczpList = this.dataForm.xczp ? JSON.parse(this.dataForm.xczp) : [];

            })
          }
        })
      },
      // 表单提交
      dataFormSubmit() {
				this.$set(this.dataForm, 'xczp', JSON.stringify(this.xczpList));

        this.$refs['elForm'].validate((valid) => {
          if (valid) {
            if (!this.dataForm.id) {
              request({
                url: '/api/System/qyscKf',
                method: 'post',
                data: this.dataForm,
              }).then((res) =>{
                this.$message({
                  message: res.msg,
                  type: 'success',
                  duration: 1000,
                  onClose: () =>{
                    this.visible = false;
                    this.$emit('refresh', true);
                  }
                })
              })
            } else {
              request({
                url: '/api/System/qyscKf/' + this.dataForm.id,
                method: 'PUT',
                data: this.dataForm
              }).then((res) =>{
                this.$message({
                  message: res.msg,
                  type: 'success',
                  duration: 1000,
                  onClose: () =>{
                    this.visible = false;
                    this.$emit('refresh', true);
                  }
                })
              })
            }
          }
        })
      },

    }
  }
  </script>